package org.desktop.intbox;

import java.awt.GridLayout;
import java.io.IOException;
import java.util.Iterator;
import java.util.ServiceLoader;

import javax.swing.JComponent;
import javax.swing.JFrame;

import org.desktop.intbox.business.categories.IFileCategory;
import org.desktop.intbox.business.categories.factory.impl.XMLCategoryDefFactory;
import org.desktop.intbox.business.files.IFileTree;
import org.desktop.intbox.business.files.factory.ITreeFactory;
import org.desktop.intbox.components.treemap.TreeBuilder;
import org.desktop.intbox.components.treemap.TreeMapDisplay;

import prefuse.data.Tree;
import prefuse.util.ui.UILib;

/**
 * Test app!
 * 
 * @author nikolay.grozev
 * 
 */
public class TestApp {

	public static void main(String argv[]) throws IOException {
		UILib.setPlatformLookAndFeel();

		XMLCategoryDefFactory configFactory = new XMLCategoryDefFactory();
		IFileCategory rootCategory = configFactory.build(TestApp.class.getResourceAsStream("extensions-tree.xml"));

		ServiceLoader<ITreeFactory> loader = ServiceLoader.load(ITreeFactory.class);

		Iterator<ITreeFactory> factories = loader.iterator();
		ITreeFactory factory = factories.next();

		IFileTree fileTree = factory.build("/home/nikolay", rootCategory);
		fileTree.summarizeDisplayData(0.5);

		Tree tree = new TreeBuilder(fileTree).buildTree();
		JComponent treemap = TreeMapDisplay.createDemoComponent(tree);

		JFrame frame = new JFrame("p r e f u s e  |  t r e e m a p");
		frame.setLayout(new GridLayout(1, 1));
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setContentPane(treemap);
		frame.pack();
		frame.setVisible(true);
	}
}
